<template>
  <div class="coupon" style="position:absolute;top:0px;width:100%;">
    <div class="vux-header" v-show="isHeader">
      <div class="vux-header-left" @click="handleBack">
        <span class="vux-header-back"></span> 
        <div class="left-arrow"></div>
      </div>
      <h1 class="vux-header-title">点击返回首页</h1> <!----> 
      <div class="vux-header-right"><!----> </div>
    </div>
    <ul class="coupon_list" v-show="couponCom.length>0">
      <li class="item" v-for="(item,index) in couponCom" :key="index">
        <div class="left">
          <h2>¥ <span>{{item.value}}<span v-if="item.type=== 2" class="zhe">折</span></span></h2>
          <p>{{item.type === 1 ? '满减券' : '优惠券'}}</p>
        </div>
        <div class="right">
          <p>{{item.name}}</p>
          <p>{{item.description}}</p>
        </div>
        <div class="footer">
          <p class="date">有效期至: {{item.endDate}}</p>
        </div>
      </li>
    </ul>
    <div class="order-empty" v-show="couponCom.length===0">
			<i class="icon-order" ></i>
			<div>
				<p>没有任何优惠券</p>
			</div>
		</div>
  </div>  
</template>
<script>
import {getStore} from '@/config/mUtils'
import { dateFormat } from 'vux'
export default {
  name: 'coupon',
  data(){
    return {
      couponData:[],
      isHeader: false
    }
  },
  created(){
    this.isHeader = this.$route.query.isHeader;
  },
  mounted(){
    this.$http.get(`/coupon/openId/${getStore('wxcode')}`)
      .then(({data})=>{
        if(data.status === '200'){
          this.couponData = data.data
        }
      }).catch(err=>{
        this.$vux.toast.show({
          type: 'warn',
          text: err.data.msg,
          time: 2000
        });
      });
  },
  computed: {
    couponCom(){
      if(this.couponData !== null){
        return this.couponData.map((item)=>{
          item.endDate = dateFormat(new Date(item.endDate),'YYYY-MM-DD')
          return item;
        })
      }
    }
  },
  methods:{
    handleBack(){
      return this.$router.push({path:'/'});
    }
  }
}
</script>
<style scoped>
.order-empty{
	display: flex;
	flex-direction: column;
	align-items: center;
	align-content: center;
	-webkit-flex-direction: column;
	-webkit-align-items: center;
	-webkit-align-content: center;
	-moz-flex-direction: column;
	-moz-align-items: center;
	-moz-align-content: center;
	padding: 2.5rem 0rem;
}
.order-empty i{
	margin-bottom: .46rem;
}
.order-empty i::before{
	font-size: 1.125rem;
	padding: 1rem;
	display: inline-block;
	background-color: #e5e5e5;
	color: #fff;
	border: 1px solid transparent;
	border-radius: 50%;
	-moz-border-radius: 50%;
	-webkit-border-radius: 50%;
}
.order-empty p{
	font-size: .46rem;
	color: #aaaaaa;
}
.coupon{
  padding-top: .65rem;
  padding-bottom: .65rem;
}
.coupon_list .item{
	overflow: hidden;
	background-color: #ffffff;
  border: transparent;
  border-radius: .3rem;
  margin-bottom: 1rem;
}
.coupon_list .left,.coupon_list .right{
  display: inline-block;
  padding: .8rem .4rem;
}
.coupon_list h2{
  color: #2e9670;
  font-size: 16px;
  font-weight: 600;
}
.coupon_list h2 >span{
  font-size: 26px;
}
.coupon_list p{
  font-size: 14px;
}
.coupon_list .left{
  width: 25%;
  text-align: center;
  border-right: 2px #f2f2f2 dashed;
}
.coupon_list .left >p{
  color: #2e9670;
}
.zhe{
  font-size: 16px;
}
.coupon_list .right p:first-child{
  color: #000;
  margin-bottom: .2rem;
  font-weight: 400;
}
.coupon_list .right p:last-child{
  color:#979797; 
}
.coupon_list .footer{
  padding: .4rem;
  background-color: rgba(0,0,0,.1);
  color:#979797;
}

/*返回按钮样式*/
.vux-header {
  position: relative;
  padding: 3px 0;
  box-sizing: border-box;
  background-color: #2e9670;
}
.vux-header .vux-header-title {
  line-height: 40px;
  text-align: center;
  font-size: 18px;
  font-weight: 400;
  color: #fff;
}
.vux-header-title-area,
.vux-header .vux-header-title {
  margin: 0 88px;
  height: 40px;
  width: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vux-header .vux-header-title > span {
  display: inline-block;
}
.vux-header .vux-header-left,
.vux-header .vux-header-right {
  position: absolute;
  top: 14px;
  display: block;
  font-size: 14px;
  line-height: 21px;
  color: #ccc;
}
.vux-header .vux-header-left a,
.vux-header .vux-header-left button,
.vux-header .vux-header-right a,
.vux-header .vux-header-right button {
  float: left;
  margin-right: 8px;
  color: #ccc;
}
.vux-header .vux-header-left a:active,
.vux-header .vux-header-left button:active,
.vux-header .vux-header-right a:active,
.vux-header .vux-header-right button:active {
  opacity: 0.5;
}
.vux-header .vux-header-left {
  left: 18px;
}
.vux-header .vux-header-left .vux-header-back {
  padding-left: 16px;
}
.vux-header .vux-header-left .left-arrow {
  position: absolute;
  width: 30px;
  height: 30px;
  top: -5px;
  left: -5px;
}
.vux-header .vux-header-left .left-arrow:before {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1px solid #ccc;
  border-width: 1px 0 0 1px;
  -webkit-transform: rotate(315deg);
          transform: rotate(315deg);
  top: 8px;
  left: 7px;
}
.vux-header .vux-header-right {
  right: 15px;
}
.vux-header .vux-header-right a,
.vux-header .vux-header-right button {
  margin-left: 8px;
  margin-right: 0;
}
.vux-header .vux-header-right .vux-header-more:after {
  content: "\2022   \2022   \2022   ";
  font-size: 16px;
}
.vux-header-fade-in-right-enter-active {
  -webkit-animation: fadeinR .5s;
          animation: fadeinR .5s;
}
.vux-header-fade-in-left-enter-active {
  -webkit-animation: fadeinL .5s;
          animation: fadeinL .5s;
}
@-webkit-keyframes fadeinR {
0% {
    opacity: 0;
    -webkit-transform: translateX(150px);
            transform: translateX(150px);
}
100% {
    opacity: 1;
    -webkit-transform: translateX(0);
            transform: translateX(0);
}
}
@keyframes fadeinR {
0% {
    opacity: 0;
    -webkit-transform: translateX(150px);
            transform: translateX(150px);
}
100% {
    opacity: 1;
    -webkit-transform: translateX(0);
            transform: translateX(0);
}
}
@-webkit-keyframes fadeinL {
0% {
    opacity: 0;
    -webkit-transform: translateX(-150px);
            transform: translateX(-150px);
}
100% {
    opacity: 1;
    -webkit-transform: translateX(0);
            transform: translateX(0);
}
}
@keyframes fadeinL {
0% {
    opacity: 0;
    -webkit-transform: translateX(-150px);
            transform: translateX(-150px);
}
100% {
    opacity: 1;
    -webkit-transform: translateX(0);
            transform: translateX(0);
}
} 
</style>
